/*
#include <qstringlist.h>
#include <qfile.h>
#include <qtextstream.h>
#include "cpustat.h"

CpuStat::CpuStat()
{
    lookUp(procValues);
}

QTime CpuStat::upTime() const
{
    QTime t;
    for ( int i = 0; i < NValues; i++ )
        t = t.addSecs(int(procValues[i] / 100));

    return t;
}

void CpuStat::statistic(double &user, double &system)
{
    double values[NValues];
    //NValues为曲线数，是个枚举值，程序中被默认为4

    lookUp(values); //读入数据
/*
    double userDelta = values[User] + values[Nice]
        - procValues[User] - procValues[Nice];
    double systemDelta = values[System] - procValues[System];

    double totalDelta = 0;
    for ( int i = 0; i < NValues; i++ )
        totalDelta += values[i] - procValues[i];

    user = userDelta / totalDelta * 100.0;//100应该是指纵坐标的范围
    system = systemDelta / totalDelta * 100.0;

    for ( int j = 0; j < NValues; j++ )
        procValues[j] = values[j];

    QTime time;
    time.start();
    qsrand(time.msec()+time.second());
    user=qrand()%77;
    system=qrand()%63;
}

******************************************
  读入数据
  ****************************************
void CpuStat::lookUp(double values[NValues]) const
{
    /*QFile file("/proc/stat");
    if ( !file.open(QIODevice::ReadOnly) )
    {
        static double dummyValues[][NValues] =
        {
            { 103726, 0, 23484, 819556 },
            { 103783, 0, 23489, 819604 },
            { 103798, 0, 23490, 819688 },
            { 103820, 0, 23490, 819766 },
            { 103840, 0, 23493, 819843 },
            { 103875, 0, 23499, 819902 },
            { 103917, 0, 23504, 819955 },
        };
        static int counter = 0;
        
        for ( int i = 0; i < NValues; i++ )
            values[i] = dummyValues[counter][i];

        counter = (counter + 1) 
            % (sizeof(dummyValues) / sizeof(dummyValues[0]));
    }

    else
    {
        QTextStream textStream(&file);
        do {
            QString line = textStream.readLine();
            line = line.trimmed();
            if ( line.startsWith("cpu ") )
            {
                const QStringList valueList =
                    line.split(" ",  QString::SkipEmptyParts);
                if ( valueList.count() >= 5 )
                {
                    for ( int i = 0; i < NValues; i++ )
                        values[i] = valueList[i+1].toDouble();
                }
                break;
            }
        } while(!textStream.atEnd());
    }

}
*/
